import sys
from PyQt5.QtWidgets import QSlider, QApplication, QVBoxLayout, QHBoxLayout, QWidget, QLabel
from PyQt5.QtCore import Qt

class StyledSlider(QWidget):
    def __init__(self):
        super().__init__()
        self.setup_ui()
        self.apply_custom_style()
    
    def setup_ui(self):
        layout = QVBoxLayout()
        
        self.slider = QSlider(Qt.Horizontal)
        self.slider.setRange(0, 100)
        self.slider.setValue(50)
        
        layout.addWidget(self.slider)
        self.setLayout(layout)
    
    def apply_custom_style(self):
        custom_style = """
        /* 自定义滑块样式 */
        QSlider::groove:horizontal {
            border: 1px solid #999999;
            height: 8px;
            background: qlineargradient(x1:0, y1:0, x2:0, y2:1, 
                                      stop:0 #B1B1B1, stop:1 #c4c4c4);
            margin: 2px 0;
            border-radius: 4px;
        }
        
        QSlider::handle:horizontal {
            background: qlineargradient(x1:0, y1:0, x2:1, y2:1,
                                      stop:0 #ffffff, stop:1 #f0f0f0);
            border: 1px solid #5c5c5c;
            width: 18px;
            margin: -8px 0;
            border-radius: 9px;
        }
        
        QSlider::handle:horizontal:hover {
            background: qlineargradient(x1:0, y1:0, x2:1, y2:1,
                                      stop:0 #ffffff, stop:1 #e0e0e0);
            border: 1px solid #333333;
        }
        
        QSlider::handle:horizontal:pressed {
            background: qlineargradient(x1:0, y1:0, x2:1, y2:1,
                                      stop:0 #d0d0d0, stop:1 #c0c0c0);
        }
        
        QSlider::sub-page:horizontal {
            background: qlineargradient(x1:0, y1:0, x2:0, y2:1,
                                      stop:0 #0078d7, stop:1 #0066b4);
            border: 1px solid #005a9e;
            height: 8px;
            border-radius: 4px;
        }
        
        QSlider::add-page:horizontal {
            background: #e0e0e0;
            border: 1px solid #999999;
            height: 8px;
            border-radius: 4px;
        }
        
        /* 垂直滑块样式 */
        QSlider::groove:vertical {
            border: 1px solid #999999;
            width: 8px;
            background: qlineargradient(x1:0, y1:0, x2:1, y2:0,
                                      stop:0 #B1B1B1, stop:1 #c4c4c4);
            margin: 0 2px;
            border-radius: 4px;
        }
        
        QSlider::handle:vertical {
            background: qlineargradient(x1:0, y1:0, x2:1, y2:1,
                                      stop:0 #ffffff, stop:1 #f0f0f0);
            border: 1px solid #5c5c5c;
            height: 18px;
            margin: 0 -8px;
            border-radius: 9px;
        }
        
        /* 刻度样式 */
        QSlider::sub-page:horizontal:disabled, 
        QSlider::add-page:horizontal:disabled {
            background: #bbbbbb;
        }
        
        QSlider::handle:horizontal:disabled {
            background: #cccccc;
            border: 1px solid #999999;
        }
        """
        
        self.slider.setStyleSheet(custom_style)

if __name__ == "__main__":
    app = QApplication(sys.argv)
    window = StyledSlider()
    window.show()
    sys.exit(app.exec_())